#include "net/tcpserver.h"
#include "net/connect.h"
#include "base/timer.h"
#include "base/eventloop.h"
#include "util/mutex.h"
#include "base/log.h"
#include "base/logthread.h"
#include "MyRpc/message.h"
#include "MyRpc/rpc.h"
#include "MyRpc/rpccall.hpp"

myrpc::Message *message = nullptr;

void close_func(net_tools::net::Connect *connect)
{
  connect->Print_ip_port("close");
};
void read_func(net_tools::net::Connect *connect){};
void conn_func(net_tools::net::Connect *connect)
{
  connect->Print_ip_port("connect");
  connect->Set_read_callback(read_func);
  connect->Set_close_callback(close_func);
  char buf[512] = {};
  int count = 0;
  NT_LOG_INFO << "BEGIN" << NT_LOG_ENDL;
  while (count < 1000000)
  {
    ++count;
    if (!myrpc::Message::Make_rpc(connect, 3, buf, false, count, count, count))
    {
      break;
    }
  }
  NT_LOG_INFO << "End" << NT_LOG_ENDL;
};

int main(int argc, char *argv[])
{
  net_tools::Config config("Server");
  net_tools::Logthread log;
  message = myrpc::Message::Get_singleton();
  net_tools::Tcpserver tcp;

  tcp.Set_connect_over_callback(conn_func);
  tcp.Initserver(2, 0);
  tcp.Startserver();
};